
clear
net install dyadclust, from (https://raw.githubusercontent.com/cfbalcazar/dyadclust/main/dyadclust/) replace force all


*Exogenous effect of P2P in previous on directed dyads

use "./dyad_1.dta"

joinby parliament using ./dyad_2
drop if placeonlist_1 >= placeonlist_2
sort parliament placeonlist_1 placeonlist_2 
order parliament placeonlist_1 placeonlist_2 id_1 candidate_name_1 id_2 candidate_name_2
label define support_lab 0 "not seconded" 1 "seconded"

rename id_1 id 
rename bill_2 bill
rename motion_2 motion 
merge m:1 parliament id bill motion using ./seconder_merge_rhs_rev
drop if _merge == 2
rename _merge support_1
recode support_1 1=0 3=1
label values support_1 support_lab
rename id id_1 
rename bill bill_2 
rename motion motion_2 

rename id_2 id 
rename bill_1 bill
rename motion_1 motion 
merge m:1 parliament id bill motion using ./seconder_merge_rhs_rev
drop if _merge == 2
rename _merge support_2
recode support_2 1=0 3=1
label values support_2 support_lab
rename id id_2 
rename bill bill_1
rename motion motion_1
drop num


expand 2, gen(direction)
gen A_support_B = support_1 if direction == 0
replace A_support_B = support_2 if direction == 1

gen B_support_A = support_2 if direction == 0
replace B_support_A = support_1 if direction == 1

gen p2p_A = p2p_1 if direction == 0
replace p2p_A = p2p_2 if direction == 1

gen p2p_B = p2p_2 if direction == 0
replace p2p_B = p2p_1 if direction == 1

sort id_1 id_2 direction parliament 
by id_1 id_2 direction: gen p2p_A_previous = p2p_A[_n-1] if parliament[_n - 1] == parliament[_n] - 1 
order parliament id_1 id_2 direction p2p_A p2p_A_previous p2p_B

sort id_1 id_2 direction parliament 
by id_1 id_2 direction: gen B_support_A_previous = B_support_A[_n-1] if parliament[_n - 1] == parliament[_n] - 1 

gen miss_lag = 1 
replace miss_lag = 0 if !missing(p2p_A_previous)
replace p2p_A_previous = 99 if miss_lag 
replace B_support_A_previous = 99 if miss_lag 

gen row_id = string(parliament) + "-" + string(id_1)
gen col_id = string(parliament) + "-" + string(id_2)
encode row_id, gen(row_num)
encode col_id, gen(col_num)


*Table 5: Effects of Power to Propose in Previous Parliament on Directed Dyadic Support, by Parliament 
eststo clear
eststo: reg A_support_B p2p_A_previous if p2p_A_previous < 99 & p2p_B == 1 & parliament == 39
eststo: reg A_support_B p2p_A_previous if p2p_A_previous < 99 & p2p_B == 1 & parliament == 40
eststo: reg A_support_B p2p_A_previous if p2p_A_previous < 99 & p2p_B == 1 & parliament == 41
eststo: reg A_support_B p2p_A_previous if p2p_A_previous < 99 & p2p_B == 1 & parliament == 42
eststo: reg A_support_B p2p_A_previous if p2p_A_previous < 99 & p2p_B == 1 & parliament == 43
eststo: reg A_support_B p2p_A_previous i.parliament if p2p_A_previous < 99 & p2p_B == 1 
esttab using "Table5.rtf",   ///
		label replace nogap nobaselevels compress b(4) se(4)	///
		mtitles("39" "40" "41" "42" "43" "Pooled") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 	

bysort parliament p2p_B: tab A_support_B p2p_A_previous, col


	
*Table B.7: TOST on Pooled Effect of Power to Propose in Previous Parliament on Directed Dyadic Support
eststo clear
eststo: reg A_support_B p2p_A_previous i.parliament if p2p_A_previous < 99 & p2p_B == 1, level(90)
esttab using "TableB7.rtf",   ///
		label replace ci level(90) nogap nobaselevels compress b(3)  	///
		mtitles("pooled") ///
		scalars("N N" "r2 R2" "r2_a R2 Adj.") 	
		
		
		

*descriptives 
*number of apparent reciprocal co-sponsorships in each parliament  
gen reciprocation = 0
replace reciprocation = 1 if A_support_B == 1 & B_support_A_previous == 1

tab reciprocation if p2p_A_previous == 1 & p2p_B == 1

sort parliament id_1 id_2 direction 
list parliament candidate_name_1 candidate_name_2 direction party_major_group_1 party_major_group_2 if reciprocation == 1


*share of "compliers" -- we measure this 
*quantity by focusing solely on the legislators in previous 
*parliament who were P2P==1 and who are in the current 
*parliament: what % of them received seconds? 
gen id_A = id_1 if direction == 0
replace id_A = id_2 if direction == 1
collapse B_support_A, by(parliament p2p_A_previous id_A) 
gen supported = B_support_A > 0 if !missing(B_support_A)
tab supported if p2p_A_previous == 1


